package homework.oo4.exercise02;


public class PolymorphicDemo {
    public static void main(String[] args) {
        Animal[] animals = new Animal[5];
        animals[0] = new Dog("大紫",1,"紫");
        animals[1] = new Dog("大红",2,"红");
        animals[2] = new Chick("大花",5,"花");
        animals[3] = new Chick("大橙",9,"橙");
        animals[4] = new Fish("大青",8,"青");

        for (int i=0;i<animals.length;i++){
            animals[i].eat();
            animals[i].drink();

            if (animals[i] instanceof Dog){
                Dog g = (Dog)animals[i];
                g.lookHome();
            }
            if (animals[i] instanceof Chick){
                Chick c = (Chick)animals[i];
                c.layEggs();
            }
            if (animals[i] instanceof Swim){
                Swim s = (Swim)animals[i];
                s.swim();
            }
        }

        Master master = new Master();
        Dog dog = new Dog("小黑",4,"黑");
        Chick chick = new Chick("小粉",5,"粉");
        Fish fish = new Fish("大红",9,"红");
        master.feed(dog);
        master.feed(chick);
        master.feed(fish);
    }
}
